package main

import (
	"context"
	"fmt"
	"github.com/go-redis/redis/v8"
	"strconv"
	"sync"
	"time"
)

func main() {
	client := redis.NewClient(&redis.Options{
		Addr: "43.154.132.143:6379",
		Password: "daslsw080706",
		DB:0,
		PoolSize: 100,
		WriteTimeout: 1000 * time.Second,
	})
	wg := sync.WaitGroup{}

	for i := 0; i < 100; i++ {
		wg.Add(1)
		go func(time, size int) {
			defer wg.Done()
			offset := time * 1000
			val := ""
			for j := 0; j < size; j++ {
				val += "a"
			}
			kv := make(map[string]interface{})
			for j := 0; j < 1000; j, offset = j+1, offset+1 {
				k := "test_" + strconv.Itoa(offset)
				kv[k] = val
			}
			err := client.MSet(context.Background(), kv).Err()
			if err != nil {
				fmt.Printf("err in %d goRoutine, content is %s\n", time, err.Error())
			}
		}(i, 1024 * 5)
	}

	wg.Wait()
}